home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
- Path: news.inap.net!news1!ind-004-236-183
- From: dlmiller@iquest.net (Doug Miller)
- Subject: Re: How can I check whether I file exists in a multi-user environment?
- X-Nntp-Posting-Host: ind-004-236-183.iquest.net
- Message-ID: <Dp6sqL.Buz@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net> <4jjn1d$clu@solutions.solon.com>
- Date: Mon, 1 Apr 1996 14:13:31 GMT
-
- seebs@solutions.solon.com (Peter Seebach) wrote:
- >In article <Dp1oM8.Cns@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
- >> * * * * C A U T I O N * * * *
- >>Although this will work in many implementations, to the best of my knowledge
- >>it is *NOT* ANSI C.
- >
- >Then why post it to comp.lang.c? Why not just email it to the user, along
- >with a pointer to the correct newsgroup? (Which is even in the newsgroups
- >list...)
- >
- >>#include <io.h>
- >>int file_exists (char *filename) {
- >> return (access(filename, 0) == 0);
- >>} /* returns -1 if file exists, 0 if it does not */
- >
- >The reason this is a poor solution is that it doesn't test for existance,
- >it tests for accessibility.
-
- You should check your facts more carefully. You evidently are unfamiliar with the behavior of
- access( ). It is defined thusly:
-
- #include <io.h>
- int access (const char *filename, int amode);
-
- permissible values for amode are:
- 06 check for read and write permission
- 04 check for read permission
- 02 check for write permission
- 01 execute
- >>>> 00 check for existence of file <<<<<
-
- Return value: If the requested access is allowed, access() returns 0; otherwise it returns a value
- of -1, and the global variable errno is set to one of the following:
- ENOENT Path or file name not found
- EACCES Permission denied
-
- As I coded it, this is a test for the existence of the file, not its accessibility.
-
-
- In modern environments, such as NT or Unix,
- >it is quite possible for a file to exist but be inaccessible. There is
- >no real way in such environments to test for existance; you aren't allowed to
- >know whether someone else has a file they don't want you to know about.
- >
- >Also, on any POSIX-like system, access is in <unistd.h>. This may be useful
- >to someone planning to work with multiple systems, or in any event NT, which
- >has some POSIX to it.
- >
- >-s
- >--
- >Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
-
-